using UnityEngine;

namespace VoxelGame.NPC
{
	public class BlobShadow : MonoBehaviour
	{
		[SerializeField]
		private Transform _model;

		[SerializeField]
		private Material _material;

		private float _initialScale;

		private void Start()
		{
			Vector3 localScale = base.transform.localScale;
			_initialScale = localScale.x;
		}

		private void Update()
		{
			if (Physics.Raycast(base.transform.position, Vector3.down, out RaycastHit hitInfo, 20f))
			{
				float num = _initialScale / Mathf.Max(hitInfo.distance, _initialScale);
				_model.transform.localScale = new Vector3(num, num, num);
				Vector3 point = hitInfo.point;
				point.y += 0.15f;
				_model.transform.position = point;
			}
			else
			{
				_model.transform.localScale = Vector3.zero;
			}
		}

		public void SetAmbientLight(float light)
		{
			_material.SetFloat("_Alpha", light / 2f);
		}
	}
}
